Skip to content

Add ucontext_t and {get,set,make,swap}context for powerpc64-linux #3986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgiessing
Copy link

@mgiessing mgiessing commented Oct 17, 2024

Description

This PR will add ucontext_t to powerpc64le-unknown-linux-gnu.
The relevant header files this is linked to can be found here: https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h and for ucontext_t specifically here: https://github.com/bminor/glibc/blob/a6eb8285d9bfb7ec0875b85ca356e833ff964d4f/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h#L155-L196

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

Testing throws an error, but that is not related to this PR as far as I can see. Even without the patch I see an error in the main branch

[...]
  cargo:warning=57833 |             }
  cargo:warning=      |             ^
  cargo:warning=/root/git/libc/target/powerpc64le-unknown-linux-gnu/debug/build/libc-test-0e970a92698d6386/out/main.c: In function ‘__test_fn_epoll_pwait2’:
  cargo:warning=/root/git/libc/target/powerpc64le-unknown-linux-gnu/debug/build/libc-test-0e970a92698d6386/out/main.c:57858:13: error: control reaches end of non-void function [-Werror=return-type]
  cargo:warning=57858 |             }
  cargo:warning=      |             ^
  cargo:warning=At top level:
  cargo:warning=cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
  cargo:warning=cc1: all warnings being treated as errors

  --- stderr
  rust version: 1.84.0-nightly


  error occurred: Command "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-Wall" "-Wextra" "-Werror" "-Wno-unused-parameter" "-Wno-type-limits" "-Wno-address-of-packed-member" "-Wno-unknown-warning-option" "-Wno-deprecated-declarations" "-D_GNU_SOURCE" "-D__GLIBC_USE_DEPRECATED_SCANF" "-o" "/root/git/libc/target/powerpc64le-unknown-linux-gnu/debug/build/libc-test-0e970a92698d6386/out/4d9447838b1b2e62-main.o" "-c" "/root/git/libc/target/powerpc64le-unknown-linux-gnu/debug/build/libc-test-0e970a92698d6386/out/main.c" with args cc did not execute successfully (status code exit status: 1).

@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@mgiessing
Copy link
Author

Related to #3964

@mgiessing
Copy link
Author

I see there is an issue with the PR in regards to the usage of of c_double/float64.

error[E0277]: the trait bound `f64: core::cmp::Eq` is not satisfied
  --> src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs:43:9
   |
43 |         pub fp_regs: [::c_double; 33], // # define __NFPREG    33
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::cmp::Eq` is not implemented for `f64`, which is required by `[f64; 33]: core::cmp::Eq`
   |
   = help: the following other types implement trait `core::cmp::Eq`:
             i128
             i16
             i32
             i64
             i8
             isize
             u128
             u16
           and 4 others
   = note: required for `[f64; 33]` to implement `core::cmp::Eq`
note: required by a bound in `AssertParamIsEq`
  --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:359:1
   = note: this error originates in the derive macro `Eq` which comes from the expansion of the macro `s` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `f64: Hash` is not satisfied
  --> src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs:43:9
   |
43 |         pub fp_regs: [::c_double; 33], // # define __NFPREG    33
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Hash` is not implemented for `f64`, which is required by `[f64; 33]: Hash`
   |
   = help: the following other types implement trait `Hash`:
             i128
             i16
             i32
             i64
             i8
             isize
             u128
             u16
           and 4 others
   = note: required for `[f64; 33]` to implement `Hash`
   = note: this error originates in the derive macro `Hash` which comes from the expansion of the macro `s` (in Nightly builds, run with -Z macro-backtrace for more info)

@JohnTitor Would you know what I need to change to make this pass? I tried to adapt based on the aarch64, loongarch64 & riscv64 version with the help of the powerpc64 glibc ucontext header file but apparently something's going wrong!

Any help is appreciated!

@mgiessing
Copy link
Author

@rustbot label stable-nominated

@rustbot rustbot added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Oct 22, 2024
@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2024

I think this looks fine, but could you please add links to the relevant headers in the PR description?

@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2024

@rustbot author

(just comment @rustbot review once the above is done)

@mgiessing
Copy link
Author

@tgross35 Thanks for looking into this! I updated the PR description with the relevant header files.

@bors
Copy link
Contributor

bors commented Nov 17, 2024

☔ The latest upstream changes (presumably #4070) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

@mgiessing this will need a rebase since the align module is gone now (which is a great thing 🎉)

@mgiessing
Copy link
Author

I'm currently not having access to my laptop so the earliest I can work again on this will be mid of December, more probably beginning of next year :-)

@tgross35
Copy link
Contributor

No worries! I'll mark this as a draft.

Any chance you know the answer to https://github.com/rust-lang/libc/pull/3986/files#r1831808892? If so, maybe somebody could pick this up to finish it.

@tgross35 tgross35 marked this pull request as draft November 20, 2024 19:53
@mgiessing
Copy link
Author

Ah, although it is quite some time I believe I used signal.h for that:

image

https://refspecs.linuxbase.org/LSB_2.1.0/LSB-Core-PPC64/LSB-Core-PPC64.html

@mgiessing
Copy link
Author

@tgross35 Sorry for late response but I finally rebased this PR and integrated everything into mod.rs :)
Could you have a look and let me know if there is some more work required or ready to merge?
Thanks!

@mgiessing
Copy link
Author

@tgross35 just checking in - have you had a chance to look into this PR when you get a moment? No rush if you're busy :-)

Comment on lines +242 to +255
#[allow(missing_debug_implementations)]
#[repr(align(8))]
pub struct mcontext_t {
__glibc_reserved: [c_ulong; 4],
pub signal: c_int,
__pad0: c_int,
pub handler: c_ulong,
pub oldmask: c_ulong,
pub regs: *mut pt_regs,
pub gp_regs: [c_ulong; __NGREG],
pub fp_regs: [c_double; __NFPREG],
pub v_regs: *mut vrregset_t,
pub vmx_reserve: [c_long; __NVRREG + __NVRREG + 1],
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a pub type gregset_t = [c_ulong; __NGREG] and use it here, same for fp_regs.

Also is this supposed to have an align repr? I don't see that at https://github.com/bminor/glibc/blob/a6eb8285d9bfb7ec0875b85ca356e833ff964d4f/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h#L120-L150

Comment on lines +225 to +240
#[allow(missing_debug_implementations)]
pub struct pt_regs {
pub gpr: [c_ulong; 32],
pub nip: c_ulong,
pub msr: c_ulong,
pub orig_gpr3: c_ulong,
pub ctr: c_ulong,
pub link: c_ulong,
pub xer: c_ulong,
pub ccr: c_ulong,
pub softe: c_ulong,
pub trap: c_ulong,
pub dar: c_ulong,
pub dsisr: c_ulong,
pub result: c_ulong,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the PR description with a permalink to the source in UAPI?

Comment on lines +1057 to +1060
pub fn getcontext(ucp: *mut ucontext_t) -> c_int;
pub fn setcontext(ucp: *const ucontext_t) -> c_int;
pub fn makecontext(ucp: *mut ucontext_t, func: extern "C" fn(), argc: c_int, ...);
pub fn swapcontext(uocp: *mut ucontext_t, ucp: *const ucontext_t) -> c_int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +193 to +206
#[repr(align(8))]
pub struct clone_args {
pub flags: c_ulonglong,
pub pidfd: c_ulonglong,
pub child_tid: c_ulonglong,
pub parent_tid: c_ulonglong,
pub exit_signal: c_ulonglong,
pub stack: c_ulonglong,
pub stack_size: c_ulonglong,
pub tls: c_ulonglong,
pub set_tid: c_ulonglong,
pub set_tid_size: c_ulonglong,
pub cgroup: c_ulonglong,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35
Copy link
Contributor

tgross35 commented Aug 10, 2025

Sorry, this wasn't on my radar at all: it's marked as a draft and "S-waiting-on-author" :) I un-drafted it, you can update the latter by commenting @rustbot review when you have made these changes (or using the UI:
image
)

A few small comments above. Could you please also remove #[allow(missing_debug_implementations)]? The s/s_no_extra_traits macros should add it.

@tgross35 tgross35 changed the title Added ucontext_t for powerpc64-linux Added ucontext_t and {get,set,make,swap}context for powerpc64-linux Aug 10, 2025
@tgross35 tgross35 changed the title Added ucontext_t and {get,set,make,swap}context for powerpc64-linux Add ucontext_t and {get,set,make,swap}context for powerpc64-linux Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-gnu O-linux O-unix S-waiting-on-author S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants